# 基础类
# 配置跨域

import tornado.web

# websocket库
import tornado.websocket


# 声明websocket基础类
class WsBaseHandler(tornado.websocket.WebSocketHandler):


	# 跨域支持
	def check_origin(self,origin):

		return True

	# 连接成功
	def open(self):

		self.write_message(" hello world ")

	# 断开链接
	def on_close(self):

		self.write_message(" bye bye ")


# 声明基类
class BaseHandler(tornado.web.RequestHandler):


	# 重写父类方法
	def set_default_headers(self):

		# 设置请求头信息
		print("开始设置")
		# 域名信息
		self.set_header("Access-Control-Allow-Origin","*")
		# 请求信息
		self.set_header("Access-Control-Allow-Headers","x-requested-with")
		# 请求方式
		self.set_header("Access-Control-Allow-Methods","POST,GET,PUT,DELETE")

	def post(self):

		self.write("这里是post请求")

	def get(self):
		self.write("这里是get请求")

	def put(self):
		self.write("这里是put请求")

	def delete(self):
		self.write("这里是delete请求")

	def options(self,*args):

		#设置状态吗
		self.set_status(204)
		self.finish()



